home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: Jack <avilev@netvision.net.il>
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: scramble game algorithm?
- Date: Sat, 30 Mar 1996 07:02:54 -0800
- Organization: NetVision LTD.
- Message-ID: <315D4D1E.734B@netvision.net.il>
- References: <3157B388.3F20@sapiens.com> <3159875F.7951@p3.enzian.com>
- NNTP-Posting-Host: ts005p2.pop4a.netvision.net.il
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win16; I)
-
- Jude Anthony wrote:
- >
- > Avi L. wrote:
- > > Hi there, i'm trying to figure out an algorithm for solving the
- > > famous scramble game, i've succeeded in solving most of the game
- > > however there are situations which require more logic added in
- > > order to search for a better path to move the pieces around.
- > > especially the following situation is troublesome:
- > >
- > > 1 2 3 4
- > > 5 6 7 8
- > > 9 10 11 12
- > > 14 15 13 -1.
- > >
- > > -1 == empty space.
- > > how do you get the 13 piece to its proper place and then manage
- > > to get the other pieces back to thier original position and thus
- > > solve this damn game.
- > > i know how to solve the game by hand however translating
- > > it to software code isn't so straight forward. guess
- > > life's too complex for that, eh?!
- > > thank you in advance for any information.
- >
- > You need a different algorythm, I think. Forget the logic; this can be
- > easily solved with a simple tree. Since there is no position from which
- > more than four pieces can move into the empty square, you create a tree
- > with four branches at each node. A structure with four pointers will be
- > necessary; I would also include an array specifying the board position
- > after the move has been made and an integer specifying the array index of
- > the piece moved:
- >
- > struct node_TAG
- > {
- > int moveme;
- > int board[4][4];
- > struct node_TAG *next[4];
- > } node;
- >
- > Write a recursive function to tranverse this tree. Every step, move each
- > possible tile into the space and create a new node for the new board
- > position. Compare the node to previous board configurations to make sure
- > you're not duplicating your work. Stop and return when there are no
- > non-repetetive board configurations, or you reach a node with a solved
- > board.
- >
- > If you actually create the entire tree (instead of stopping when you
- > reach your first solve), this algorythm gives you the added bonus of
- > being able to find the fewest moves necessary to solve the board.
- >
- > Thanks for making me think of this problem. I may go and write it up
- > myself, for a practical exercise. I hope this solution is more useful to
- > you.
- > No thank you for this simple and elegant solution. don't know i hadn't used trees in the
- first place. i had tried solving the problem with brute force and actually tried to simulate
- my thinking process while playing the game. it's similar to the hanoi problem algorithm.
- it is working just fine and very dynamically too, it doesn't get stuck in situations
- and knows when and how to back-track, although it checks almost all possible moves in the
- process, but hey, it solves the game and that's what's important.
-
- Thanks again,
- Later Avi L.
-